#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from model import PostClassM
from model import TopicM
from model import LectureM

class updateHandler(webapp.RequestHandler):
    def get(self):
        lectureKey = self.request.get('lectureKey')
        topicKey = self.request.get('topicKey')
        understand = self.request.get('understand')
        total = self.request.get('total')
        
        if lectureKey and topicKey:
            topic=TopicM.getTopicByKey(topicKey)
            lecture=LectureM.getLectureByKey(lectureKey)
            PostClassM.saveVotesStats(lecture, topic, int(total), int(understand))
        else:
            #return error
            pass
             
application = webapp.WSGIApplication([(r'.*', updateHandler)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()